<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>司机管理管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
	
checkCard = function()  
{  
    var card = document.getElementById('idnumber').value;  
    //校验生日  
    checkBirthday(card);
  //检验性别
    if (parseInt(card.substr(16, 1)) % 2 == 1){
    	$(gender).val("男");
    }else{
    	$(gender).val("女");
    }
    return true;  
};  
  
  
//检查号码是否符合规范，包括长度，类型  
isCardNo = function(card)  
{  
    //身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X  
    var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/;  
    if(reg.test(card) === false)  
    {  
        return false;  
    }  
  
    return true;  
};  
 
//检查生日是否正确  
checkBirthday = function(card)  
{  
    var len = card.length;  
    //身份证15位时，次序为省（3位）市（3位）年（2位）月（2位）日（2位）校验位（3位），皆为数字  
    if(len == '15')  
    {  
        var re_fifteen = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/;   
        var arr_data = card.match(re_fifteen);  
        var year = arr_data[2];  
        var month = arr_data[3];  
        var day = arr_data[4];  
        var birthday = new Date('19'+year+'/'+month+'/'+day);  
        var brithdayDrv = year +"/"+month+"/"+day;
        $(drvbirth).val(brithdayDrv);
        return verifyBirthday('19'+year,month,day,birthday);  
    }  
    //身份证18位时，次序为省（3位）市（3位）年（4位）月（2位）日（2位）校验位（4位），校验位末尾可能为X  
    if(len == '18')  
    {  
        var re_eighteen = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/;  
        var arr_data = card.match(re_eighteen);  
        var year = arr_data[2];  
        var month = arr_data[3];  
        var day = arr_data[4];  
        var birthday = new Date(year+'/'+month+'/'+day);  
        var brithdayDrv = year +"/"+month+"/"+day;
        $(drvbirth).val(brithdayDrv);
        return verifyBirthday(year,month,day,birthday);  
    }  
    return false;  
};  
  
//校验日期  
verifyBirthday = function(year,month,day,birthday)  
{  
    var now = new Date();  
    var now_year = now.getFullYear();  
    //年月日是否合理  
    if(birthday.getFullYear() == year && (birthday.getMonth() + 1) == month && birthday.getDate() == day)  
    {  
        //判断年份的范围（3岁到100岁之间)  
        var time = now_year - year;  
        if(time >= 3 && time <= 100)  
        {  
            return true;  
        }  
        return false;  
    }  
    return false;  
};  
  
//校验位的检测  
checkParity = function(card)  
{  
    //15位转18位  
    card = changeFivteenToEighteen(card);  
    var len = card.length;  
    if(len == '18')  
    {  
        var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);   
        var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');   
        var cardTemp = 0, i, valnum;   
        for(i = 0; i < 17; i ++)   
        {   
            cardTemp += card.substr(i, 1) * arrInt[i];   
        }   
        valnum = arrCh[cardTemp % 11];   
        if (valnum == card.substr(17, 1))   
        {  
            return true;  
        }  
        return false;  
    }  
    return false;  
};  
  
//15位转18位身份证号  
changeFivteenToEighteen = function(card)  
{  
    if(card.length == '15')  
    {  
        var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);   
        var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');   
        var cardTemp = 0, i;     
        card = card.substr(0, 6) + '19' + card.substr(6, card.length - 6);  
        for(i = 0; i < 17; i ++)   
        {   
            cardTemp += card.substr(i, 1) * arrInt[i];   
        }   
        card += arrCh[cardTemp % 11];   
        return card;  
    }  
    return card;  
};  
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				rules: {
					idnumber: {remote: "${ctx}/driver/tDrivers/checkIdnumber?oldIdnumber=" + encodeURIComponent('${tDrivers.idnumber}')},
					mobile: {remote: "${ctx}/driver/tDrivers/checkMobile?oldMobile=" + encodeURIComponent('${tDrivers.mobile}')},
					drvlicno: {remote: "${ctx}/driver/tDrivers/checkDrvlicno?oldDrvlicno=" + encodeURIComponent('${tDrivers.drvlicno}')}
				},
				messages: {
					idnumber: {remote: "身份证号已存在"},
					mobile: {remote: "手机号已存在"},
					drvlicno: {remote: "驾驶证号已存在"}
				},
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			$("input").prop("disabled", true);
			$("select").prop("disabled", true);
			$("#btnCancel").prop("disabled", false);
		});
		//验证手机号
		function checkPhone(){

			var sPhone = document.getElementById("mobile").value ;

			if(!/^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test(sPhone))
			{
			  alert("输入手机号码有误");
			}

		}; 
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/driver/tDrivers?types=${types}">司机管理列表</a></li>
		<li class="active"><a href="${ctx}/driver/tDrivers/formview?id=${tDrivers.id}&types=${types}">司机详细信息</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="tDrivers" method="post" class="form-horizontal">
		<input type="hidden" id="types" name="types" value="${types}">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<!-- <div class="control-group">
			<label class="control-label">司机编号：</label>
			<div class="controls">
				<form:input path="drvssysid" htmlEscape="false" class="span4 required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div> -->
		<div class="control-group">
			<label class="control-label">归属公司：</label>
			<div class="controls">
				<c:if test="${types!=1}">
				 	<select name="office" class="span4 required" >
					<option value="">--请选择--</option>
					<c:forEach items="${officelist}" var="office">
						<option value="${office.id}"
							<c:if test="${office.id eq tDrivers.office.id}">selected="selected"</c:if>>
							${office.name}</option>
					</c:forEach>
				</select>
					
				</c:if>
				<c:if test="${types==1}">
					<input type="text" id="office" name="office.id" value="${tDrivers.office.name}" readonly="readonly" class="span4">
				</c:if>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
			
		</div>
		<div class="control-group">
			<label class="control-label">姓名：</label>
			<div class="controls">
				<form:input path="drvname" htmlEscape="false" maxlength="30" class="span4 required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">手机号：</label>
			<div class="controls">
				<form:input path="mobile" htmlEscape="false" maxlength="20" class="span4 mobile required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">是否本公司：</label>
			<div class="controls">
				<form:select path="belong" class="span4">
					<form:option value="1" label="本公司" />
					<form:option value="0" label="外公司" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">身份证号：</label>
			<div class="controls">
				<form:input path="idnumber" htmlEscape="false" maxlength="18" class="span4 card required" onblur="checkCard();"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">性别：</label>
			<div class="controls">
				<%-- <form:select path="gender">
					<form:options items="${fns:getDictList('sex')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select> --%>
				<form:input path="gender" htmlEscape="false" maxlength="2" class="span4 " readonly="true"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">出生年月日：</label>
			<div class="controls">
				<%-- <input name="drvbirth" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate "
					value="<fmt:formatDate value="${tDrivers.drvbirth}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/> --%>
					<form:input path="drvbirth" htmlEscape="false"  class="span4 " readonly="true"/>
			</div>
		</div>
	<%-- 	<div class="control-group">
			<label class="control-label">司机状态：</label>
			<div class="controls">
				<form:input path="drvstatus" value="空闲" htmlEscape="false" maxlength="10" class="span4 "/>
			</div>
		</div> --%>
		<div class="control-group">
			<label class="control-label">司机属性：</label>
			<div class="controls">
				<form:select path="drvattr" class="span4">
					<form:option value="" label="" />
					<form:options items="${fns:getDictList('drvattr')}"
						itemLabel="label" itemValue="value" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		
		
		<div class="control-group">
			<label class="control-label">驾驶证号：</label>
			<div class="controls">
				<form:input path="drvlicno" htmlEscape="false" maxlength="20" class="span4 required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">驾照类型：</label>
			<div class="controls">
				<%-- <form:input path="permittype" htmlEscape="false" maxlength="20" class="span4 "/>
					<select  name="permittype" class="span4">  
  					<option value ="1"
  					<c:if test="${not empty tDrivers.permittype and 1 eq tDrivers.permittype}">selected="selected"</c:if>>2</option>  
  					<option value ="2"
  					<c:if test="${not empty tDrivers.permittype and 2 eq tDrivers.permittype}">selected="selected"</c:if>>4</option>  
  					<option value ="3"
  					<c:if test="${not empty tDrivers.permittype and 3 eq tDrivers.permittype}">selected="selected"</c:if>>6</option>  
				</select> --%>
				<form:select path="permittype" class="span4 required">
					<form:option value="" label="" />
					<form:options items="${fns:getDictList('permittype')}"
						itemLabel="label" itemValue="value" htmlEscape="false" />
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">驾驶证初领日期：</label>
			<div class="controls">
				<input name="collardate" type="text" readonly="readonly"  class="span4 Wdate required"
					value="<fmt:formatDate value="${tDrivers.collardate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
					<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">上岗证号：</label>
			<div class="controls">
				<form:input path="worklicno" htmlEscape="false" maxlength="20" class="span4 digits"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">文化程度：</label>
			<div class="controls">
				<%-- <form:select path="education" class="span4">
					<option value="">--请选择--</option>
					<option value="1"
						<c:if test="${not empty tDrivers.education and 1 eq tDrivers.education}">selected="selected"</c:if>>小学</option>
					<option value="2"
						<c:if test="${not empty tDrivers.education and 2 eq tDrivers.education}">selected="selected"</c:if>>初中</option>
					<option value="3"
						<c:if test="${not empty tDrivers.education and 3 eq tDrivers.education}">selected="selected"</c:if>>高中</option>
					<option value="4"
						<c:if test="${not empty tDrivers.education and 4 eq tDrivers.education}">selected="selected"</c:if>>中专</option>
					<option value="5"
						<c:if test="${not empty tDrivers.education and 5 eq tDrivers.education}">selected="selected"</c:if>>大专</option>
					<option value="6"
						<c:if test="${not empty tDrivers.education and 6 eq tDrivers.education}">selected="selected"</c:if>>本科</option>
					<option value="7"
						<c:if test="${not empty tDrivers.education and 7 eq tDrivers.education}">selected="selected"</c:if>>研究生</option>
					<option value="8"
						<c:if test="${not empty tDrivers.education and 8 eq tDrivers.education}">selected="selected"</c:if>>博士</option>
				</form:select> --%>
				<form:select path="education" class="span4">
					<form:option value="" label="" />
					<form:options items="${fns:getDictList('dbo_education')}"
						itemLabel="label" itemValue="value" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">民族：</label>
			<div class="controls">
				<form:input path="nationality" htmlEscape="false" maxlength="20" class="span4 "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">服务等级：</label>
			<div class="controls">
				<%-- <form:select path="serverclass" class="span4">
					<option value="">--请选择--</option>
					<option value="1"
						<c:if test="${not empty tDrivers.serverclass and 1 eq tDrivers.serverclass}">selected="selected"</c:if>>金牌</option>
					<option value="2"
						<c:if test="${not empty tDrivers.serverclass and 2 eq tDrivers.serverclass}">selected="selected"</c:if>>银牌</option>
					<option value="3"
						<c:if test="${not empty tDrivers.serverclass and 3 eq tDrivers.serverclass}">selected="selected"</c:if>>铜牌</option>
				</form:select> --%>
				<form:select path="serverclass" class="span4">
					<form:option value="" label="" />
					<form:options items="${fns:getDictList('dbo_serverclass')}"
						itemLabel="label" itemValue="value" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">血型：</label>
			<div class="controls">
				<%-- <select  name="bloodtype" class="span4">  
					<option value="">--请选择--</option>
  					<option value ="1"
  					<c:if test="${not empty tDrivers.bloodtype and 1 eq tDrivers.bloodtype}">selected="selected"</c:if>>A型</option>  
  					<option value ="2"
  					<c:if test="${not empty tDrivers.bloodtype and 2 eq tDrivers.bloodtype}">selected="selected"</c:if>>B型</option>  
  					<option value="3"
  					<c:if test="${not empty tDrivers.bloodtype and 3 eq tDrivers.bloodtype}">selected="selected"</c:if>>AB型</option> 
  					<option value="4"
  					<c:if test="${not empty tDrivers.bloodtype and 4 eq tDrivers.bloodtype}">selected="selected"</c:if>>O型</option>   
				</select>  --%>
				<form:select path="bloodtype" class="span4">
					<form:option value="" label="" />
					<form:options items="${fns:getDictList('dbo_bloodtype')}"
						itemLabel="label" itemValue="value" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">户籍所在地：</label>
			<div class="controls">
				<form:input path="census" htmlEscape="false" maxlength="80" class="span4 "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">现居住地：</label>
			<div class="controls">
				<form:input path="address" htmlEscape="false" maxlength="80" class="span4 "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">联系电话：</label>
			<div class="controls">
				<form:input path="hometel" htmlEscape="false" maxlength="20" class="span4 phone"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">入职时间：</label>
			<div class="controls">
				<input name="entrytype" type="text" readonly="readonly"  class="span4 Wdate "
					value="<fmt:formatDate value="${tDrivers.entrytype}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">合同期限：</label>
			<div class="controls">
				<form:input path="contractperiod" htmlEscape="false" maxlength="30" class="span4 "/>
			</div>
		</div>
		<div class="form-actions">
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>